home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / RequiredFinderColors / RequiredFinderColors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-14  |  3.9 KB  |  177 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    RequiredFinderColors                                    */
  4. /*                                                                            */
  5. /*    Description:    Under system 7, the finder switches to the black&white    */
  6. /*                    version of all the desktop icons when certain required    */
  7. /*                    colors aren't available in the device's color table.    */
  8. /*                    This snippet shows which colors are needed in the        */
  9. /*                    system color table for the desktop icons to be            */
  10. /*                    displayed in their color version.  Also with these        */
  11. /*                    colors, the apple icon in the menu bar will remain in    */
  12. /*                    color as well.                                            */
  13. /*                                                                            */
  14. /*    Files:            RequiredFinderColors.π                                    */
  15. /*                    RequiredFinderColors.π.rsrc                                */
  16. /*                    RequiredFinderColors.c                                    */
  17. /*                                                                            */
  18. /*    Programmer:        Edgar Lee                                                */
  19. /*    Organization:    Apple Computer, Inc.                                    */
  20. /*    Department:        Developer Technical Support, DTS                        */
  21. /*    Language:        C (Think C version 5.0.2)                                */
  22. /*    Date Created:    09-02-92                                                */
  23. /*                                                                            */
  24. /****************************************************************************/
  25.  
  26. /* Constant Declarations */
  27.  
  28. #define    WWIDTH    500
  29. #define    WHEIGHT    100
  30.  
  31. #define WLEFT    (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
  32. #define WTOP    (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
  33.  
  34. void initMac();
  35. void setUpMenus();
  36.  
  37. void createWindow();
  38. void drawWindow();
  39. void doEventLoop();
  40.  
  41. main()
  42. {
  43.     initMac();
  44.     setUpMenus();
  45.     
  46.     createWindow();
  47.     
  48.     doEventLoop();
  49. }
  50.  
  51. void initMac()
  52. {
  53.     MaxApplZone();
  54.  
  55.     InitGraf( &thePort );
  56.     InitFonts();
  57.     InitWindows();
  58.     InitMenus();
  59.     TEInit();
  60.     InitDialogs( nil );
  61.     InitCursor();
  62.     FlushEvents( 0, everyEvent );
  63. }
  64.  
  65. void createWindow()
  66. {
  67.     Rect            rect;
  68.     WindowPtr        window;
  69.     PaletteHandle    palette;
  70.     
  71.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  72.     window = NewCWindow( 0L, &rect, "\pRequired Finder Colors", true, documentProc,
  73.                             (WindowPtr)-1L, true, 0L );                        
  74.     SetPort( window );
  75.     
  76.     TextMode( srcXor );
  77.     TextFont( geneva );
  78.     TextSize( 9 );
  79.     
  80.     palette = GetNewPalette( 128 );
  81.     SetPalette( window, palette, true );
  82. }
  83.  
  84. void setUpMenus()
  85. {
  86.     int            i;
  87.     Handle        menuHandle;
  88.     
  89.     if ((menuHandle = GetNewMBar( 128 )) == nil)
  90.         ExitToShell();
  91.         
  92.     SetMenuBar( menuHandle );
  93.     AddResMenu( GetMenu( 128 ), 'DRVR' );
  94.         
  95.     DrawMenuBar();
  96.     ReleaseResource( menuHandle );
  97. }
  98.  
  99. void drawWindow()
  100. {
  101.     int            i;
  102.     int            numEntries;
  103.     int            lineWidth;
  104.     RGBColor    color;
  105.     Str255        string;
  106.     
  107.     numEntries = 10;
  108.     lineWidth = WWIDTH / numEntries;
  109.     
  110.     PenSize( lineWidth, 1 );
  111.     
  112.     for (i = 0; i < numEntries; i++)
  113.     {
  114.         PmForeColor( i );
  115.         MoveTo( i * lineWidth, 0 );
  116.         LineTo( i * lineWidth, WHEIGHT );
  117.         
  118.         Index2Color( i, &color );
  119.         
  120.         MoveTo( i * lineWidth + 5, WHEIGHT * 3 / 8 );
  121.         DrawString( "\pRGB:" );
  122.         
  123.         NumToString( color.red, string );
  124.         MoveTo( i * lineWidth + 5, WHEIGHT / 2 );
  125.         DrawString( string );
  126.         
  127.         NumToString( color.green, string );
  128.         MoveTo( i * lineWidth + 5, WHEIGHT * 5 / 8 );
  129.         DrawString( string );
  130.         
  131.         NumToString( color.blue, string );
  132.         MoveTo( i * lineWidth + 5, WHEIGHT * 6 / 8 );
  133.         DrawString( string );
  134.     }
  135. }
  136.  
  137. void doEventLoop()
  138. {
  139.     EventRecord     event;
  140.     WindowPtr       window;
  141.     short              clickArea;
  142.     Rect               screenRect;
  143.  
  144.     for (;;)
  145.     {
  146.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  147.         {
  148.             if (event.what == mouseDown)
  149.             {
  150.                 clickArea = FindWindow( event.where, &window );
  151.                 
  152.                 if (clickArea == inDrag)
  153.                 {
  154.                     screenRect = (**GetGrayRgn()).rgnBBox;
  155.                     DragWindow( window, event.where, &screenRect );
  156.                 }
  157.                 else if (clickArea == inContent)
  158.                 {
  159.                     if (window != FrontWindow())
  160.                         SelectWindow( window );
  161.                 }
  162.                 else if (clickArea == inGoAway)
  163.                     if (TrackGoAway( window, event.where ))
  164.                         return;
  165.             }
  166.             else if (event.what == updateEvt)
  167.             {
  168.                 window = (WindowPtr)event.message;    
  169.                 SetPort( window );
  170.                 
  171.                 BeginUpdate( window );
  172.                 drawWindow();
  173.                 EndUpdate( window );
  174.             }
  175.         }
  176.     }
  177. }